package com.myzk.example.utils.common;

/**
 * @author mayong
 * @date 2020年04月11日
 */
public class PathUtils {
	/**
	 * 合并路径
	 * @param basePath 基础路径
	 * @param pathAdd 要合并添加的路径
	 * @return
	 */
	public static String concatPath(String basePath, String... pathAdd) {
		if (basePath == null) {
			return null;
		}
		StringBuilder builder = new StringBuilder(basePath);
		if (pathAdd != null) {
			for (String path : pathAdd) {
				builder.append("/").append(path);
			}
		}
		return clearPath(builder.toString());
	}

	/**
	 * 清除路径中多余的分隔符
	 * @param path
	 * @return
	 */
	private static String clearPath(String path) {
		if (path == null) {
			return null;
		}
		return path.replaceAll("[\\\\/]+", "/");
	}

	public static void main(String[] args) {
		String clearPath = concatPath("/home","mayong","/");
		System.out.println(clearPath);
	}
}
